using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Emlyn.Website.Articles;
using Emlyn.Website.ArticlesPresentation;
using System.Collections.Generic;

public partial class Software : EmlynPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        const string C_DefaultArticle = "SoftwareMain";

        string lArticleCode = null;

        if (Request.QueryString["code"] != null)
            lArticleCode = Request.QueryString["code"];

        if (lArticleCode == null)
            lArticleCode = C_DefaultArticle;

        ArticleQuery larticleQuery = new ArticleQuery();
        Article larticle = larticleQuery.GetArticleByArticleCode(lArticleCode);

        if (larticle != null)
        {
            //string lcurrentPath = System.IO.Path.GetFullPath(".");
            //Label llabel = new Label();
            //llabel.Text = lcurrentPath;
            //pnlBody.Controls.Add(llabel);

            //
            // ArticleList details
            //
            PresentArticleDetail lpad = new PresentArticleDetail();
            lpad.aArticle = larticle;
            lpad.Editable = false;
            //            lpad.CssClass = pnlBody.CssClass;
            pnlBody.Controls.Add(lpad);

            IList<Article> lChildArticles = larticleQuery.GetArticlesForParentArticleID(larticle.ArticleID);
            if (lChildArticles.Count > 0)
            {
                PresentArticleList lpal = new PresentArticleList();
                lpal.aPresentArticleFactory = new PresentArticleTitleLinkFactory(); //  new PresentArticleDetailFactory();
                lpal.aPresentArticleFactory.aEditable = false;
                lpal.aArticleList = lChildArticles;
                lpal.aPresentArticleFactory.aNavigateUrl =
                    "SoftwareItem.aspx?code=%ArticleCode%";
                //lpal.CssClass = pnlBody.CssClass;

                pnlBody.Controls.Add(lpal);
            }

            IList<Article> lParentArticles = larticleQuery.GetArticlesForChildArticleID(larticle.ArticleID);
            if (lParentArticles.Count > 0)
            {
                PresentArticleList lpal = new PresentArticleList();
                lpal.aPresentArticleFactory = new PresentArticleTitleLinkFactory();
                lpal.aPresentArticleFactory.aEditable = false;
                lpal.aPresentArticleFactory.aNavigateUrl = Page.Request.Url.AbsolutePath + "?code=%ArticleCode%";
                lpal.Title = "Up to:";
                //lpal.CssClass = pnlRight.CssClass;
                lpal.aArticleList = lParentArticles;

                pnlRight.Controls.Add(lpal);
            }
        }
        else
        {
            Label llbl = new Label();
            llbl.Text = "ArticleList \"" + C_DefaultArticle + "\" not found.";
            pnlBody.Controls.Add(llbl);
        }
    }
}
